package com.hexb.arithmetic.llk
{
	
	import flash.display.Graphics;
	
	public class LLKTestTools
	{
		/**绘制连接线
		 * @parameter g graphics对象
		 * @parameter points 路径列表
		 * @parameter width 网格宽度
		 * @parameter height 网格高度
		 * @parameter offsetX 相对于容器X轴偏移
		 * @parameter offsetY 相对于容器Y轴偏移
		 * */
		static public function drawConnectLine(g:Graphics,
											   points:Array,
											   width:Number,
											   height:Number,
											   offsetX:int,
											   offsetY:int,
											   color:uint=0xff000,
											   thickness:Number=2,
											   alpha:Number=0.5):void{
			var tempPoint:LPoint ;
			var i:int ;
			var tempXyArr:Array = new Array(4);
			var x:Number ;
			var y:Number ;
			g.lineStyle(thickness,color,alpha);
			tempPoint = points[0] as LPoint ;
			//计算点中心位置
			x = tempPoint.col * width + width /2 + offsetX ;
			y = tempPoint.row * height + height /2 + offsetY ;
			tempXyArr[0] = new LPoint(x,y);
			for(i=1 ;i<points.length;i++){
				g.moveTo(x,y);
				tempPoint = points[i] as LPoint ;
				if(tempPoint==null){
					continue ;
				}
				x = tempPoint.col * width + width /2 + offsetX ;
				y = tempPoint.row * height + height /2 + offsetY ;
				tempXyArr[i] = new LPoint(x,y);
				g.lineTo(x,y);
			}
		}
		
		/**绘制连接点
		 * @parameter g graphics对象
		 * @parameter points 路径列表
		 * @parameter radius 点半径
		 * @parameter colors 连接点颜色列表
		 * */
		static private function drawConnectPoint(g:Graphics,
												 points:Array,
												 radius:Number=2,
												 colors:Array=null,
												 thickness:Number=1):void{
			if(points==null){
				return ;
			}
			if(colors==null){
				colors=[0xff0000,0xfff000,0xffff00,0xfffff0]
			}
			var i:int ;
			var tempPoint:LPoint ;
			for(i=0 ;i<points.length;i++){
				tempPoint = points[i] as LPoint ;
				g.drawCircle(tempPoint.row,tempPoint.col,radius) ;
			}
		}
		
		/**
		 * 绘制背景网格
		 * */
		static public function drawGrid(g:Graphics,width:Number,height:Number,offsetX:int,offsetY:int,rowNum:int,colNum:int):void{
			//绘制水平线
			var i:int ;
			var y:Number;
			var x:Number;
			for(i=0 ;i<=rowNum;i++){
				y = offsetY + i * height ;
				x = offsetX + colNum * width;
				g.moveTo(offsetX,y);
				g.lineStyle(1,0xff0000,1);
				g.lineTo(x,y); 
			}
			//绘制垂直线
			for(i=0;i<=colNum;i++){
				y = offsetY + colNum * height ;
				x = offsetX + i * width ;
				g.moveTo(x,offsetY);
				g.lineStyle(1,0xff0000,0.5);
				g.lineTo(x,y);
			}
		}
		
		
		public function LLKTestTools()
		{
		}
	}
}